package com.intercepter;

import com.aop.LoggingAop;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;

//拦截器，拦截失败了，取不到参数
public class ParamIntecepter implements HandlerInterceptor {

    private Logger logger= LoggerFactory.getLogger(ParamIntecepter.class);

    @Override
    public boolean  preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        logger.info("请求之路径");
        logger.info(request.getRequestURI());
//        Map<String,String[]> logMaps= request.getParameterMap();
//        for (Map.Entry<String, String[]> entry : logMaps.entrySet()) {
//            // 处理参数
//            String paramName = entry.getKey();
//            System.out.println(paramName+":");
//            System.out.println("{");
//            String[] paramValues = entry.getValue();
//           for(String param: paramValues){
//               System.out.println(param);
//           }
//            System.out.println("}");
//        }
//
      //      Map<String,String[]> logMaps= request.getParameterMap();
        ////        System.out.println(logMaps);
        ////      Iterator<String> logIterator=   logMaps.keySet().iterator();
        ////       while(logIterator.hasNext()){
        ////           System.out.println(logMaps+":");
        ////
        ////       }  Enumeration<String> paramNames = request.getParameterNames();
//        while (paramNames.hasMoreElements()) {
//            String paramName = paramNames.nextElement();
//            System.out.println(paramName);
//            // 获取每个参数名对应的值
//            String paramValues = request.getParameter(paramName);
//            // 处理参数
//            System.out.println(paramValues);
//        }
        return true;
    }
}
